package org.dant.ant.extension.net.rmi;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import org.dant.ant.extension.tasks.internal.RemoteCommand;
import org.dant.ant.extension.tasks.internal.RemoteResponse;
import org.dant.ant.extension.net.Dispatcher;
import org.dant.ant.extension.net.DefaultDispatcher;

public class DistributedAntImpl extends UnicastRemoteObject implements DistributedAnt {

  protected Dispatcher dispatcher = new DefaultDispatcher();
  private String fullURL;

  public void setDispatcher(Dispatcher d) {
    this.dispatcher = d;
  }

  public void setFullURL(String fullURL) {
    this.fullURL = fullURL;
  }
  
  public DistributedAntImpl() throws RemoteException {
    super();
  }

  public RemoteResponse remoteCall(RemoteCommand rCmd) throws RemoteException {
    RemoteResponse response = new RemoteResponse();
    response.setFullURL(fullURL);
    dispatcher.dispatch(rCmd, response);
    return response;
  }

}

